<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../css/api.css" />
		<link rel="stylesheet" type="text/css" href="../../css/style.css" />
		<style type="text/css">
			html,body { background-color:#F7F8FA; height:100%; }
			.sys_info{ padding: 0 15px 25px;}
			.sys_info li{ padding-top:20px; text-align: center;}
			.sys_info i{ display:inline-block; padding: 0 20px; font-size: 12px; background-color: #e0e0e0; color: #fff; line-height: 20px; border-radius: 10px;}
			.sys_info li a{ position:relative; margin-top: 15px; text-align: left; display: block; padding: 15px 25px 15px 15px; background: url(../../image/img_13.png) no-repeat 96% center; background-size: 5px auto; background-color: #fff; border-radius: 4px; box-shadow: 0 5px 20px rgba(0,0,0,0.08);}
			.sys_info h4{ display:block; font-size: 15px; color: #333; font-weight: 600; line-height: 25px;}
			.sys_info p{ font-size: 13px; color: #999; margin-top: 2px;}
			.sys_info p em{ color:#1c63fa; text-decoration: underline;}
			.sys_info li.on a{ background:#fff;}
			.redpoint{ position: absolute; right: 22px; top: 35px; width: 8px; height: 8px; background-color: #ff2e4c; border-radius: 50%;}
			
			.sk-three-bounce {
			  margin: 0 auto;
			  width: 80px;
			  text-align: center; }
			  .sk-three-bounce .sk-child {
				width: 13.5px;
				height: 13.5px;
				background-color: #3262F1;
				border-radius: 100%;
				display: inline-block;
				-webkit-animation: sk-three-bounce 1.4s ease-in-out 0s infinite both;
						animation: sk-three-bounce 1.4s ease-in-out 0s infinite both; }
			  .sk-three-bounce .sk-bounce1 {
				-webkit-animation-delay: -0.32s;
						animation-delay: -0.32s; }
			  .sk-three-bounce .sk-bounce2 {
				-webkit-animation-delay: -0.16s;
						animation-delay: -0.16s; }

			@-webkit-keyframes sk-three-bounce {
			  0%, 80%, 100% {
				-webkit-transform: scale(0);
						transform: scale(0); }
			  40% {
				-webkit-transform: scale(1);
						transform: scale(1); } }

			@keyframes sk-three-bounce {
			  0%, 80%, 100% {
				-webkit-transform: scale(0);
						transform: scale(0); }
			  40% {
				-webkit-transform: scale(1);
						transform: scale(1); }
			}
			.display-none { display:none; }
			.text-center { text-align: center !important; }
		</style>
	</head>
	<body>
		<div class="sys_info">
			<ul id="msgslist">
			</ul>
			<script id="msgslist_template" type="text/template">
				{{ for (var i = 0, len = it.length; i < len; i++) { }}
				{{? it[i].msgtype == 1}}
				<li>
					<i>{{=it[i].createtime}}</i>
					<a href="javascript:;" tapmode="lipress" data-msgid="{{=it[i].id}}" onclick="readmsg(this)">
						{{? it[i].readstatus == 0}}<em id="redpoint_{{=it[i].id}}" class="redpoint"></em>{{?}}
						<h4>{{=it[i].title}}</h4>
					</a>
				</li>
				{{?? it[i].msgtype == 2 || it[i].msgtype == 4}}
				<li class="on">
					<i>{{=it[i].createtime}}</i>
					<a href="##" title="">
						
						<h4>{{=it[i].title}}</h4>
						<p>{{=it[i].content}}</p>
					</a>
				</li>
				{{?? it[i].msgtype == 3}}
				<li>
					<i>{{=it[i].createtime}}</i>
					<a href="javascript:;" tapmode="lipress" data-msgid="{{=it[i].id}}" onclick="readmsg(this)">
						{{? it[i].readstatus == 0}}<em id="redpoint_{{=it[i].id}}" class="redpoint"></em>{{?}}
						<h4>{{=it[i].title}}</h4>
						<p><em>查看原因</em></p>
					</a>
				</li>
				{{?}}
				{{ } }}
			</script>
		</div>
		
		<div class="text-center display-none" style="padding: 110px 0 !important;" id="divnodata">
			<div class="text-center"><img src="../../image/nodata.png" style="margin:0 auto;width:41px;height:auto;"></div>
			<p class="text-center" style="font-size:12px;color:#9f9f9f;margin-top:15px;">暂时没有消息</p>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/app.js"></script>
	<script type="text/javascript" src="../../script/doT.js"></script>
	<script type="text/javascript">
		var page = 1;
		var UILoading;
		apiready = function() {
			api.parseTapmode();
			UILoading = api.require('UILoading');
			$api.css($api.dom('.sys_info'), 'display: none');
			showloading();
			getJsonFromAPI();
			api.addEventListener({
                name: 'navitembtn'
            }, function(ret, err) {
                if (ret.type == 'left') {
					api.closeWin({
					});
                }
            });
			api.addEventListener({
					name:"scrolltobottom"
			},function(ret,err){
				getJsonFromAPI()
			});
			api.addEventListener({
				name : 'reloadpage'
			}, function(ret, err) {
				refreshPage();				
			});
		}
		function refreshPage() {
			page = 1;
			getJsonFromAPI();
		}
		function readmsg(obj) {
			var msgid = $api.attr(obj,'data-msgid');
			$api.remove($api.byId("redpoint_"+msgid));
			
			var noread = 0;
			var liList = $api.domAll('.redpoint');
			noread = liList.length;
			if(noread == 0)
			{
				//清除个人中心红点
				api.execScript({
					name: 'root',
					frameName: 'msg_frm',
					script: 'setredpoint();'
				});
			}
			openNavWin('#ddd','sysmsgdetail_win','sysmsgdetail_frm.html','消息详情',false,false,true,[],{msgid:msgid});
		}
		function getJsonFromAPI() {
			//从接口获取查询数据
			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret.value) {
					var userinfo = JSON.parse(ret.value);
					api.ajax({
						url: ApiUrl + '/v1/msgs/'+page,
						method: 'get',
						cache: false,
						timeout: 10,
						headers: {
							authorization: kAppKey+';'+userinfo.access_token+';'+userinfo.uid
						}
					}, function(ret, err) {
						hideloading();
						$api.css($api.dom('.sys_info'), 'display: block');
						if (ret) {
							if(ret.list.length > 0)
							{
								$api.addCls($api.byId('divnodata'),'display-none');
								var isAppend = true;
								if(page==1)
								{
									isAppend = false;
								}
								page++;
								var msgslist = ret.list;
								UpdateList('msgslist','msgslist_template',msgslist,isAppend);
							}
							else
							{
								if(page==1)
								{
									UpdateList('msgslist','msgslist_template',ret.list,false);
									$api.removeCls($api.byId('divnodata'),'display-none');
								}
							}
							api.sendEvent({
								name : 'changeredpoint',
								extra : {
									msgjson : {sysnoreadmsg:ret.sysnoreadmsg,friendnoreadmsg:ret.friendnoreadmsg}
								}
							});
							api.execScript({
								name: 'root',
								frameName: 'home_frm',
								script: 'reloadUnreadCount();'
							});
						} else {
							if(err.statusCode==402)
							{
								Relogin();
							}
							else
							{
								console.log(JSON.stringify(err));
								toast('网络异常');
							}
						}
					});
				}
			});
		}
		//渲染数据
		function UpdateList(domId,templateId,jsondata,isAppend) {
			//console.log(JSON.stringify(jsondata));
			var act_content = $api.byId(domId);
			var tempFn = doT.template($api.byId(templateId).innerHTML);
			var resultText = tempFn(jsondata);
			//alert(isAppend);
			if(isAppend)
			{
				$api.append(act_content, resultText);
			}
			else
			{
				$api.html(act_content, resultText);
			}
			//console.log(resultText);
			api.parseTapmode();
		}
	</script>
</html>